import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

class MyThreadPool {
    BlockingQueue<Runnable> queue = new LinkedBlockingDeque<>();
    public void submit(Runnable task) throws InterruptedException {
        queue.put(task);
    }

    public MyThreadPool(int n) {
        for(int i = 0;i < n;i++) {
            Thread t = new Thread(() -> {
                while(true) {
                    try {
                        Runnable task = queue.take();
                        task.run();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            t.start();
        }
    }
}

public class ThreadDemo {
    public static void main(String[] args) throws InterruptedException {
        ArrayList<Integer> array = new ArrayList<>();
        HashMap<Integer,Integer> map = new HashMap<>();
        MyThreadPool pool = new MyThreadPool(10);
        for (int i = 0; i < 1000; i++) {
            int time = i;
            pool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello " + time);
                }
            });
        }
        Thread.sleep(3000);
    }
}
